package com.lfg.leetcode.leetcode1000;


import java.util.HashMap;
import java.util.Map;

public class No1189maxNumberOfBalloons {
    public static void main(String[] args) {
        System.out.println(maxNumberOfBalloons("balon"));
    }

    public static int maxNumberOfBalloons(String text) {
        String content = "balloon";
        int ret = Integer.MAX_VALUE;
        Map<Character, Integer> count = new HashMap<>();
        Map<Character, Integer> target = new HashMap<>();
        for (int i = 0; i < text.length(); i++) {
            count.merge(text.charAt(i), 1, Integer::sum);
        }
        for (int i = 0; i < content.length(); i++) {
            target.merge(content.charAt(i), 1, Integer::sum);
        }
        for (Map.Entry<Character, Integer> entry : target.entrySet()) {
            if (!count.containsKey(entry.getKey())) {
                return 0;
            }
            ret = Math.min(count.remove(entry.getKey()) / entry.getValue(), ret);
        }

        return ret;
    }

}

